﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bigger.Study.ConsoleApp.PostSharp.CustomLogging
{
    public class CustomLoggingExample : IExample
    {
        [LogSetValue]
        private int Value;
        public void Execute()
        {
            // Demonstrate that we can create a nice hierarchical log including parameter and return values.
            Value = Fibonacci(5);

            // Demonstrate how exceptions are logged.
            try
            {
                Fibonacci(-1);
            }
            catch
            {
            }

            // Demonstrate that we can add logging to system methods, too.
            Console.WriteLine(Math.Sin(5));
        }

        private int Fibonacci(int n)
        {
            if (n < 0)
                throw new ArgumentOutOfRangeException();
            if (n == 0)
                return 0;
            if (n == 1)
                return 1;

            return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}
